package platform.server.common.utils;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * @Title: MD5Utils
 * @ProjectName com-bigwavn-group
 * @Description: MD5Utils-登录密码
 * @author: wangweitao 1749343503@qq.com
 * @date: 2019/5/10 17:01
 * @version: V1.0.0
 */
public class MD5Utils {
    private static final String SALT = "bigwavn";

    private static final String ALGORITH_NAME = "md5";

    private static final int HASH_ITERATIONS = 2;

    public static String encrypt(String pswd) {
        String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(SALT), HASH_ITERATIONS).toHex();
        return newPassword;
    }

    public static String encrypt(String username, String pswd) {
        String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(username + SALT),
                HASH_ITERATIONS).toHex();
        return newPassword;
    }
    public static void main(String[] args) {

        System.out.println(MD5Utils.encrypt("xiaolang", "xiaolang"));
    }
}
